<template>
  <div class="login_con">
    <div class="login_box">
        <div class="avatar_box">
          <img src="../assets/logo.png">
        </div>
        <el-form ref="form" :model="form" :rules="loginForm" class="FormBox">
          <el-form-item prop="userName">
            <el-input v-model="form.userName" prefix-icon="iconfont icon-wode1"></el-input>
          </el-form-item>
          <el-form-item prop="passWord">
            <el-input v-model="form.passWord" type="password" prefix-icon="el-icon-discount"></el-input>
          </el-form-item>
          <el-form-item class="btn">
            <el-button type="primary" @click="LoginForm">登录</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      form: {
        userName: '',
        passWord: ''
      },
      loginForm: {
        userName: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        passWord: [
          { required: true, message: '请选输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    LoginForm () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$message({
            message: '登录成功',
            type: 'success'
          })
          // 保存token
          window.sessionStorage.setItem('token', '123456')
          this.$router.push('/home')
        }
      })
    },
    resetForm () {
      this.$refs.form.resetFields()
    }
  }
}
</script>

<style lang="less" scoped>
.login_con{
  background: #2b4b6b;
  height: 100%;
}
.login_box{
  width: 450px;
  height: 300px;
  background: #ffffff;
  border-radius: 5px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  .avatar_box{
      width: 130px;
      height: 130px;
      border-radius: 50%;
      border: 1px solid #eee;
      padding: 10px;
      box-shadow: 0 0 10px #ddd;
      position: absolute;
      left: 50%;
      transform: translate(-50%,-50%);
      background: #fff;
    img{
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background: #eee;
    }
  }
}
.FormBox{ position: absolute; bottom: 0; width: 100%; padding: 0 20px; box-sizing: border-box}
.btn{
  display: flex; justify-content: flex-end;
}
</style>
